/*
	指定一个小时段，以及昨天和上周相同一个小时段的线图对比
*/
define(
	[
		'require',
		'apm/ui/business_chart_line'
	],
	function (require) {
		"use strict";

		var forEach = Ember.EnumerableUtils.forEach;

		var LineChartView = require("apm/ui/business_chart_line").extend({
			_translateXAxis: function(option){
				var view = this;
				var data = this.get("data");
				var xAxisData = option.xAxis[0].data = [];
				forEach(data[0], function(performance){
					xAxisData.push(view._translateXAxisDataItem(performance));
				});
			},

			_translateSeries: function(option){
				var view = this;
				var data = this.get("data");
				var index = 3;
				forEach(data, function(performances,i){
					var name,
						backgroundColor,
						borderColor;
					if(index){
						switch(index){
							case 1:
							  name = "今 天 " + APM.util.formatDate(performances[0].timestamp, "yyyy-M-d");
							  backgroundColor = "rgba(248,206,105,.3)";
							  borderColor = "#f8ce69";
							  index--;
							  break;
							case 2:
							  name = "昨 天 " + APM.util.formatDate(performances[0].timestamp, "yyyy-M-d");
							  backgroundColor = "rgba(0,221,255,.36)";
							  borderColor = "#00ddff";
							  index--;
							  break;
							case 3:
							  name = "上 周 " + APM.util.formatDate(performances[0].timestamp, "yyyy-M-d");
							  backgroundColor = "rgba(4,218,148,.3)";
							  borderColor = "#04da94";
							  index--;
							  break;
						}
					}else{
						name = APM.util.formatDate(performances[0].timestamp, "yyyy-M-d");
					}
					var serieConfig = {
						name: name,
						type:'line',
						itemStyle: {normal: {
							color: borderColor,
							areaStyle: {type: 'default',color:backgroundColor},lineStyle:{width:1,color:"#f8ce69"}}
						},
						symbol: 'circle',
						symbolSize: 2,
						showAllSymbol: true,
						smooth:true,
						data:[]
					};
					option.series.push(serieConfig);

					forEach(performances, function(performance){
						serieConfig.data.push(view._translateSeriesDataItem(performance[view.get("dataKey")]));
					});
				});
			},

			_translateOther: function(option){
				this._super(option);

				option.legend.y = 30;
				option.grid.y = 60;
				var data = this.get("data");
				var index = 3;
				forEach(data, function(performances){
					if(index){
						switch(index){
							case 1:
							  option.legend.data.push("今 天 " + APM.util.formatDate(performances[0].timestamp, "yyyy-M-d"));
							  index--;
							  break;
							case 2:
							  option.legend.data.push("昨 天 " + APM.util.formatDate(performances[0].timestamp, "yyyy-M-d"));
							  index--;
							  break;
							case 3:
							  option.legend.data.push("上 周 " + APM.util.formatDate(performances[0].timestamp, "yyyy-M-d"));
							  index--;
							  break;
						}
					}else{
						option.legend.data.push(APM.util.formatDate(performances[0].timestamp, "yyyy-M-d"));
					}
				});
			},

			_tooltipFormatter: function(type){
				var sName = this.get("sName");
				return function(params, ticket, callback){
					params = Ember.A(params||[]);
					var formatter = APM.util.indicatorFormatter(type);
					var tooltip = sName;
					params.forEach(function(param){
						tooltip +=  '<br/>' + param.seriesName + '：' + formatter(param.data.orgiVal);
					});
					return tooltip;
				}
			}
		});

		return LineChartView;
	}
);